#include "bsp_gpio.h"
#include "def.h"

#if APP_ID  == 0
T_GpioCfgStru myGpioCfgArray[ADPT_LED_NUM] = {
	{
		.clk = RCU_GPIOB,
		.port = GPIOB,
		.pin = GPIO_PIN_0,
		.mode = GPIO_OTYPE_PP,
		.speed = GPIO_OSPEED_50MHZ,
		.initState = RESET,
		.strArray = {"SysRun"},
	},
	{
		.clk = RCU_GPIOA,
		.port = GPIOA,
		.pin = GPIO_PIN_0,
		.mode = GPIO_OTYPE_PP,
		.speed = GPIO_OSPEED_50MHZ,
		.initState = RESET,
		.strArray = {"Alarm"},
	},
	{
		.clk = RCU_GPIOC,
		.port = GPIOC,
		.pin = GPIO_PIN_0,
		.mode = GPIO_OTYPE_PP,
		.speed = GPIO_OSPEED_50MHZ,
		.initState = RESET,
		.strArray = {"Error"},
	},
	{
		.clk = RCU_GPIOA,
		.port = GPIOA,
		.pin = GPIO_PIN_9,
		.mode = GPIO_AF_7,
		.speed = GPIO_OSPEED_50MHZ,
		.initState = RESET,
		.strArray = {"Com0Tx"},
	},
	{
		.clk = RCU_GPIOA,
		.port = GPIOA,
		.pin = GPIO_PIN_10,
		.mode = GPIO_AF_7,
		.speed = GPIO_OSPEED_50MHZ,
		.initState = RESET,
		.strArray = {"Com0Rx"},
	},
	{
		.clk = RCU_GPIOB,
		.port = GPIOB,
		.pin = GPIO_PIN_2,
		.mode = GPIO_AF_7,
		.speed = GPIO_OSPEED_50MHZ,
		.initState = RESET,
		.strArray = {"Com1Tx"},
	},
	{
		.clk = RCU_GPIOB,
		.port = GPIOB,
		.pin = GPIO_PIN_3,
		.mode = GPIO_AF_7,
		.speed = GPIO_OSPEED_50MHZ,
		.initState = RESET,
		.strArray = {"Com1Rx"},
	},
};
#endif

int32_t AdptGpioInitFun(T_GpioCfgStru *ptrGpioCfg, uint32_t len)
{
    RETURN_ERROR_IF(ptrGpioCfg == NULL || len == 0);
	int32_t gpioNum = len;
	for (int32_t i = 0; i < gpioNum; i++) {
	    /* enable the led clock */
		rcu_periph_clock_enable(ptrGpioCfg[i].clk);
		/* configure led GPIO port */ 
//		gpio_init(ptrGpioCfg[i].port, ptrGpioCfg[i].mode, ptrGpioCfg[i].speed, ptrGpioCfg[i].pin);

        if (ptrGpioCfg[i].initState == SET) {
			gpio_bit_set(ptrGpioCfg[i].port, ptrGpioCfg[i].pin);
		} else {
			gpio_bit_reset(ptrGpioCfg[i].port, ptrGpioCfg[i].pin);
		}
	}
	return 0;
}
